﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TaxiDispatchClient
{
    public partial class AdMachineListForm : DevExpress.XtraEditors.XtraForm
    {
        public AdMachineListForm()
        {
            InitializeComponent();
            
        }

        private void AdMachineListForm_Load(object sender, EventArgs e)
        {
            Thread t = new Thread(BindData);
            t.IsBackground = true;
            t.Start();
        }

        private void BindData()
        {
            DataSet ds = null;
            for (int i = 0; i < 5; i++)
            {
                ds = MainForm.PositionService.AdMachineGetList("");
                if (ds!=null && ds.Tables.Count>0)
                {
                    BeginInvoke(new MethodInvoker(() =>
                        {
                            gridControl1.DataSource = ds.Tables[0];
                            gridView1.GroupPanelText = "共有"+
                                ds.Tables[0].Rows.Count+"条数据";
                        }
                        ));
                    break;
                }
                Thread.Sleep(1000);
            }
            if (ds==null)
            {
                XtraMessageBox.Show("未能从服务器获取到信息！");    
            }
            
        }

        private void btn_exportToExcel_Click(object sender, EventArgs e)
        {
            saveFileDialog1.FileName = "广告机信息列表";
            saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                gridView1.ExportToXls(saveFileDialog1.FileName);
                XtraMessageBox.Show("Excel导出完成！");
            }
        }

        #region 窗体控件效果
        Point _mouseOff;
        bool _leftFlag;
        private void Form_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _mouseOff = new Point(-e.X, -e.Y);
                _leftFlag = true;
            }
        }

        private void Form_MouseMove(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(_mouseOff.X, _mouseOff.Y);
                Location = mouseSet;
            }
        }

        private void Form_MouseUp(object sender, MouseEventArgs e)
        {
            if (_leftFlag)
            {
                _leftFlag = false;
            }
        }

        private void pictureEdit_exit_MouseHover(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexit;
            Cursor = Cursors.Hand;
        }

        private void pictureEdit_exit_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.Image = Properties.Resources.snedSmsexitPressDown;

            Cursor = Cursors.Arrow;

        }
        private void btn_MouseHover(object sender, EventArgs e)
        {
            Cursor = Cursors.Hand;
        }

        private void btn_MouseLeave(object sender, EventArgs e)
        {
            Cursor = Cursors.Arrow;
        }

        private void pictureEdit_exit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void PhoneUserForm_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Close();
            }
        }
        #endregion

    }
}